package game.display;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

import game.menu.Drawable;

/** Creates a background 
 * 
 * @author DMEComputer
 *
 */

public class Background implements Drawable 
{
	private static int width;
	private static int height;
	
	private ArrayList<Drawable> stuff;
	
	/** Constructs the backgrounds view
	 * 
	 * @param width the width of the background 
	 * @param height the height of the background
	 * @param s maximum number of stars that should be displayed from the view of the player
	 * @param a maximum number of asteroids that should be displayed from the view of the player
	 */
	
	public Background(int width, int height, int s, int a )
	{
		this.width = width;
		this.height = height;
		
		stuff = new ArrayList<Drawable>();
		
		for(int count = 0; count < s; count++)
		{
			stuff.add(new Star(((Math.random())*width),((Math.random())*height),(1 - 2*(Math.random())), (1 - 2*(Math.random()))));
		}
		for(int count = 0; count < a; count++)
		{
			stuff.add(new Asteroid(((Math.random())*width),((Math.random())*height),(1 - 2*(Math.random())), (1 - 2*(Math.random()))));
		}
	}
	
	/** Returns the background width
	 * 
	 * @return the background width
	 */
	
	public static int getWidth()
	{
		return width;
	}
	
	/** Returns the background height
	 * 
	 * @return the background height
	 */
	
	public static int getHeight()
	{
		return height;
	}

	/** Draws the background
	 * 
	 */
	
	@Override
	public void draw(Graphics g) 
	{
		g.setColor(Color.BLACK);
		g.fillRect(0, 0, width, height);
		
		for(Drawable d: stuff){
			if(d instanceof Star)
			{
				((Star) d).update();
			}
			else{
				((Asteroid) d).update();
			}
			d.draw(g);
		}
	}
}
